package xuanzhen.dating.service.impl;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import xuanzhen.dating.dao.DatingMapper;
import xuanzhen.dating.dao.SeeShareMapper;
import xuanzhen.dating.pojo.DatingUser;
import xuanzhen.dating.pojo.SeeShare;
import xuanzhen.dating.pojo.SignList;
import xuanzhen.dating.service.DatingService;
@Service
public class DatingServiceImpl implements DatingService {
	@Resource
	DatingMapper datingMapper;
	@Resource
	SeeShareMapper seeShareMapper;
	@Override
	public List<DatingUser> selectDatingUser(int pageNo) throws Exception {
		int recordNo = pageNo*10;
		return datingMapper.queryDatingUser(recordNo);
	}

	@Override
	public int addDatingUser(DatingUser datingUser) throws Exception {
		Date now = new Date();
		SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");// 可以方便地修改日期格式
		String nowTime = dateFormat.format(now);
		datingUser.setCreateTime(nowTime);
		datingMapper.addDatingUser(datingUser);
		List<DatingUser> user =  datingMapper.queryDatingUserByUser(datingUser);
		int tag = 0;
		if(user != null){
			tag=1;
		}
		return tag;
	}

	@Override
	public void addweShare(DatingUser duser)throws Exception {
		datingMapper.addShareCount(duser);
		
	}

	@Override
	public int countRecords() throws Exception {
		int count = datingMapper.countDatingUser();
		if(count%10==0){
			count = count/10;
		}else{
			count = count/10+1;
		}
		return count;
	}

	@Override
	public List<SignList> selectSignList() throws Exception {
		// TODO Auto-generated method stub
		return datingMapper.selectSignList();
	}

	@Override
	public List<DatingUser> selectDatingUserBykey(int pageNo, String key) throws Exception {
		Map<String,Object> param = new HashMap();
		int s = pageNo*10;
		param.put("recordNo",s );
		param.put("key", key);
		return datingMapper.selectDatingUserByKey(param);
	}

	@Override
	public List<DatingUser> selectAll() throws Exception {
		// TODO Auto-generated method stub
		return datingMapper.selectAll();
	}

	@Override
	public int countRecordsBySignTime(String string) throws Exception {
		// TODO Auto-generated method stub
		return datingMapper.countDatingUserBySignTime(string);
	}


}
